import type { OrderType } from '@/enums'
import type { PageParams } from '@/types/consult'
import type {
  OrderPre,
  AddressItem,
  AddAddress,
  OrderDetail,
  Express,
  PrescriptionPage,
  MedicalPage,
} from '@/types/medicine'
import request from '@/utils/request'

// 查询药品订单预支付信息
export const getMedicalOrderPreService = (params: { prescriptionId: string }) =>
  request.get<OrderPre>('/patient/medicine/order/pre', { params })

// 获取收货地址列表
export const getAddressListService = () => request.get<AddressItem[]>('/patient/order/address')

// 新增收货地址
export const addAddressService = (data: AddAddress) =>
  request.post<{
    id: string
  }>('/patient/order/address', data)

// 修改收货地址
export const updateAddressService = (data: AddAddress, id: string) =>
  request.put<{
    id: string
  }>(`/patient/order/address/${id}`, data)

// 删除收货地址
export const deleteAddressService = (id: string) =>
  request.delete<{
    id: string
  }>(`/patient/order/address/${id}`)

// 查询收货地址详情
export const getAddressDetailService = (id: string) =>
  request.get<AddressItem>(`/patient/order/address/${id}`)

// 生成药品订单
export const createMedicineOrderService = (data: { id: string; addressId: string }) => {
  return request.post<{
    id: string
  }>('/patient/medicine/order', data)
}
// 查询药品订单详情
export const getMedicalOrderDetailService = (id: string) => {
  return request.get<OrderDetail>(`/patient/medicine/order/detail/${id}`)
}
// 查询物流信息
export const getExpressService = (id: string) => {
  return request.get<Express>(`/patient/order/${id}/logistics`)
}

// 查询处方列表
export const getPrescriptionListService = (params: PageParams) => {
  return request.get<PrescriptionPage>('/patient/consult/prescription', { params })
}

// 查询药品订单列表
export const getMedicalListService = (
  params: PageParams & {
    status: OrderType
  },
) => {
  return request.get<MedicalPage>('/patient/medicine/order/mylist', { params })
}
// 确认收货
export const confirmReceiveService = (id: string) => {
  return request.put(`/patient/order/confirm/${id}`)
}
